import React from 'react';

class LifePrc extends React.Component{
    constructor(props){
        super(props);
        this.state = {
            count:0
        }
    }

    handleAdd = ()=>{
        this.setState({
            count:this.state.count+1
        });
    }

    handleClick(){
        this.setState({
            count:this.state.count+1,
        });
    }

    componentDidMount(){
        console.log('componetDidMount finished');
    }

    componentWillUnmount(){
        console.log('componentWillUnmount');
    }

    componentWillReceiveProps(newProps){
        console.log('this is new props :'+newProps.name);
    }

    componentWillMount(){
        console.log('componentWillMount');
    }

    componentWillUpdate(){
        console.log('componet will update');
    }

    shouldComponentUpdate(){
        console.log('shouldComponetUpdate');
        return true;//if return false ,component will not update
    }


    render(){
        console.log('render');
        return <div>
            <h1>this is LifePrc</h1>
            <button onClick={this.handleAdd}>clickOne</button>
            <button onClick={this.handleClick.bind(this)}>clickTwo</button>
            <p>{this.state.count}</p>
        </div>
    }
}

export default LifePrc;